<template>
  <view class="tabbar-box">
    <template v-for="(item,index) in menus" :key="index">
      <view class="menu-item" :class="{active:tabbar.currentIndex===index}" @click="tabClick(index)">
        <view class="iconfont" :style="{backgroundImage:`url(${item.icon})`}"></view>
        <text>{{ item.name }}</text>
      </view>
    </template>
  </view>
</template>

<script setup>
import {ref} from 'vue'
import {tabbarStore} from '@/stores/tabbar.js'
const tabbar = tabbarStore()
const menus = ref([
  {
    name: "首页",
    icon: "/static/tabbar/index.png",
    path: "/pages/index/index"
  },
  {
    name: "映射",
    icon: "/static/tabbar/tools.png",
    path: '/pages/map/index'
  },
  {
    name: "我的",
    icon: "/static/tabbar/me.png",
    path: '/pages/personal/index'
  }
])

const tabClick = (index) => {
  tabbar.setCurrentIndex(index)
  const path = menus.value[index].path
  console.log("path:" + path);
  console.log("index:" , index);
  setTimeout(() => {
    uni.switchTab({
      url: path
    })
  }, 300)// 与CSS过渡时间保持一致
}

</script>

<style lang="scss" scoped>

.iconfont {
  width: 48rpx;
  height: 48rpx;
  background-position: center;
  background-repeat: no-repeat;
  background-size: contain;
  margin-bottom: 4rpx;
}

.tabbar-box {
  background: rgba(255, 255, 255, 0.5);
  backdrop-filter: blur(20rpx);
  border-radius: 140rpx ;
  height: 120rpx;
  display: flex;
  align-items: center;
  justify-content: space-around;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 20px;
  width: 80%;
  z-index: 999;
  box-shadow: 0 -4rpx 16rpx rgba(0, 0, 0, 0.05);
  padding-bottom: constant(safe-area-inset-bottom);
  padding-bottom: env(safe-area-inset-bottom);
  margin: 0 auto;
}

.menu-item {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  flex: 1;
  height: 100%;
  position: relative;
  transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.menu-item text {
  font-size: 24rpx;
  color: #666;
  margin-top: 6rpx;
  transition: color 0.3s ease, font-weight 0.3s ease;
}

.menu-item.active {
  transition: color 0.3s ease, font-weight 0.3s ease;
  .iconfont {
    transform: scale(1.1);
  }

  text {
    color: var(--bg);
    font-weight: 600;
    transition: all 0.3s;
  }
}
</style>
